using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Fulan.OutlookSyn.Objects;
using Fulan.OutlookSyn.Helper;
using Fulan.OutlookSyn.Properties;

namespace Fulan.OutlookSyn
{
    public partial class FrmSetting : Form
    {
        public FrmSetting()
        {
            NotifyIconControl.timer.Stop();
            InitializeComponent();

            SettingInfo info = SettingInfoHelper.GetSettingInfo();
            this.txtUrlAddress.Text = info.UrlAddress;
            this.txtUserName.Text = info.UserName;
            this.numRefreshTime.Value = info.RefreshTime;

            this.chkOnLoad.Checked = WindowsAutoLoad.IsAutoRun();
        }

        private void FrmSetting_Load(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            NotifyIconControl.timer.Start();
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            SettingInfo info = SettingInfoHelper.GetSettingInfo();
            info.UrlAddress = this.txtUrlAddress.Text.Trim();
            info.UserName = this.txtUserName.Text.Trim();
            info.RefreshTime = (int)this.numRefreshTime.Value;
            SettingInfoHelper.SaveInfo(info);

            if (this.chkOnLoad.Checked)
                WindowsAutoLoad.SetAutoRun();
            else
                WindowsAutoLoad.UnSetAutoRun();

            NotifyIconControl.timer.Interval = info.RefreshTime * (int.Parse(Resources.Minuite));
            NotifyIconControl.timer.Start();

            this.DialogResult = DialogResult.OK;
        }}
}